package com.shelpe.services.scheduler.item.campaign;

import java.util.Calendar;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;

import com.shelpe.services.scheduler.dto.RptCampaignDto;
import com.shelpe.services.scheduler.mongorepository.UnrecoverableErrorRepository;
import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.po.Users;
import com.shelpe.services.scheduler.syncclient.CampaignClient;
import com.shelpe.services.scheduler.util.Util;

public class RptCampaignProcessor implements ItemProcessor<Users, SyncLog>{

	private static final Logger logger = LoggerFactory.getLogger(CampaignProcessor.class);
	
	@Autowired
	private CampaignClient campClient;

	@Autowired
	private UnrecoverableErrorRepository errorRep;
	
	@Override
	public SyncLog process(Users item) throws Exception {
		// TODO Auto-generated method stub

		long userId = item.getUserId();		
		if(errorRep.countByUserId(userId) > 0){
			return null;
		}
		Calendar cal = Calendar.getInstance();	  
		int hour=cal.get(Calendar.HOUR_OF_DAY);//小时	 
		String record = hour > 8 ? "no" : "yes";
		RptCampaignDto rptDto = campClient.syncRptCampaignsByUserId(userId, record);
		
		return Util.convert(rptDto);
	}
}
